package com.baitengsoft.patentservicemonitor.job.utils;

import org.springframework.context.annotation.PropertySource;
import org.springframework.core.env.Environment;
import org.springframework.stereotype.Component;

import javax.annotation.Resource;

/**
 * @author wangze
 * @date 2018-02-12 13:44.
 **/

@Component
@PropertySource(value = "classpath:/env.properties", encoding = "UTF-8")
public class SysParametersUtil {

    @Resource
    Environment env;

    /**
     * 获取参数值
     *
     * @param propertyName
     * @return
     */
    public String getPropertyValue(String propertyName) {
        if (!env.containsProperty(propertyName)) {
            throw new RuntimeException("当前property文件不存在key");
        }
        return env.getProperty(propertyName);
    }


    public String getPatentExploredUrl() {
        return this.getPropertyValue("patentExplorerUrl");
    }


    public String getInitDataUrl() {
        return this.getPatentExploredUrl() + this.getPropertyValue("initDataUrl");
    }

    public String getInitUpdateDataUrl() {
        return this.getPatentExploredUrl() + this.getPropertyValue("initUpdateDataUrl");
    }

    public String getInitDataCallbackUrl() {
        return this.getPropertyValue("initDataCallbackUrl");
    }

    public String getInitOutDataCallbackUrl() {
        return this.getPropertyValue("initOutDataCallbackUrl");
    }

    public String getInitUpdateDataCallbackUrl() {
        return this.getPropertyValue("initUpdateDataCallbackUrl");
    }


    public String getAddOrUpdateRptUrl() {
        return this.getPropertyValue("localhost") + this.getPropertyValue("addOrUpdateRptUrl");
    }
}
